package SiTuQingYou.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import SiTuQingYou.dao.CityDao;
import SiTuQingYou.dao.SceneDao;
import SiTuQingYou.dao.ScenePhotoDao;
import SiTuQingYou.vo.City;
import SiTuQingYou.vo.Scene;
import SiTuQingYou.vo.Strategy;

@WebServlet("/GetCitySceneByCityIdServlet")
public class GetCitySceneByCityIdServlet extends BaseAction {
	private static final long serialVersionUID = 1L;
       
    public GetCitySceneByCityIdServlet() {
        super();
    }



    //获得所有城市
    protected void getAllCity(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
    	 Strategy strategy=new Strategy();
		 ArrayList<City> citys=(ArrayList<City>)CityDao.getcityd().allcity();
		 request.setAttribute("citys", citys);
	}
    //根据城市id查询城市景点信息ajax用
    protected void getcityscenebycity(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		String cityid = request.getParameter("id");
		int cid = Integer.parseInt(cityid);
		//System.out.println(cid);
		ArrayList<Scene> scenes = SceneDao.getscened().cityscene(cid);
        //System.out.println(scenes.get(0).getIntro());
		request.setAttribute("scenes", scenes);
		String scenesx="";
		for(int i=0;i<scenes.size();i++)
		{
			String scene=scenes.get(i).getScenename();
			scenesx=scenesx+","+scene;
		}
		for(int i=0;i<scenes.size();i++)
		{
			int sceneid=scenes.get(i).getId();
			scenesx=scenesx+"."+sceneid;
		}
		PrintWriter out=response.getWriter();
		out.print(scenesx);

	}
    
    
    
	protected void getcityscenebycityid(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		String cityid = request.getParameter("id");
		int cid = Integer.parseInt(cityid);
		//System.out.println(cid);
		ArrayList<Scene> scenes = SceneDao.getscened().cityscene(cid);
        //System.out.println(scenes.get(0).getIntro());
		request.setAttribute("scenes", scenes);
		ArrayList<String> pics = new ArrayList<String>();
		
		for(int i=0;i<scenes.size();i++)
		{
			int id = scenes.get(i).getId();
			String pic = ScenePhotoDao.getspd().getfirstphotobyscenesid(id);
			pics.add(pic);
		}
		request.setAttribute("pics", pics);
	}
	
	@Override
	protected void doDefault(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stubr
		
	}

}
